package cn.itcast.GsyVideoPlayer;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.VideoView;

public class VideoViewActivity extends AppCompatActivity {

    private ImageView imageView;

    private VideoView video;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        //去除标题导航栏
        getSupportActionBar().hide();

        //去除时间和电量等
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_view);

        video=this.findViewById(R.id.vv1);
        video.setVideoPath("https://media.w3.org/2010/05/sintel/trailer.mp4");
        MediaController mediaController=new MediaController(VideoViewActivity.this);//添加控制器，系统自带的
        video.setMediaController(mediaController);

        imageView=this.findViewById(R.id.ivv1);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                play();

            }
        });

        video.start();

    }


    public void play(){
        if(video.isPlaying()&&video!=null){
            imageView.setImageResource(android.R.drawable.ic_media_pause);
            video.pause();
            return;
        }

        imageView.setImageResource(android.R.drawable.ic_media_play);
        video.start();

    }


}